/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package groupe;

import java.awt.*;
import java.io.IOException;
import javax.swing.tree.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

import java.awt.*;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import view.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.border.LineBorder;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import java.util.Calendar;
import java.util.GregorianCalendar;
import view.DualListBox;
/**
 *
 * @author Ter Murga Victor
 */
public class GroupeView extends JFrame implements ActionListener{
    private JPanel mainPanel;
    private JPanel mainPanel1;
    private JPanel mainPanel2;
    private JPanel mainPanel3;
    private JPanel dualPanel=null;
    private JPanel viewPanel=null;
    private JPanel commandPanel=null;
     private JPanel comboPanel=null;
    private JScrollPane scrollPane, scrollPane2;
    private JMenuBar menuBar;
    private String url, url2, url3, url4;
    private ArrayList<Element> listBriques;
    JComboBox comboClasses;
    DualListBox dual = new DualListBox();
    NodeList nodeListClasses;
    Element rootE2, rootEl, rootGroupe;
    JTextField jTitre = new JTextField("");
    JLabel parte3=new JLabel(".xml");
    JLabel parte1;
    String NomGroupe;
    public String baseGroupe, baseProfils;
    Utility utilidad=new Utility();
    Operations ope2= new Operations();
    private JMenu menuBrique;
    String totalGroupe;

    public GroupeView(String chemin) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException {
        this.url = chemin;
        String base = url.substring(0,url.lastIndexOf("\\")-41)+"Fichiers systeme\\Parametres\\";
        url2=base+"Classes.xml";
        url3=base+"Preferences.xml";

        baseGroupe= url.substring(0,url.lastIndexOf("\\")-41)+"Fichiers utilisateur\\Profils de groupe\\";
        baseProfils= url.substring(0,url.lastIndexOf("\\")-41)+"Fichiers utilisateur\\Profils Eprofilea\\";

        System.out.println(baseGroupe);
        ResourceMap resourceMap = Application.getInstance(groupe.App.class).getContext().getResourceMap(App.class);
        setTitle(resourceMap.getString("Application.title")+" ("+url.substring(url.lastIndexOf("\\")+1,url.length())+")");
        //setIconImage(Toolkit.getDefaultToolkit().getImage(App.class.getResource("resources/visualisation.png")));
        initComponents();
        voirStructure();

    }

    private void initComponents() throws ParserConfigurationException, SAXException, IOException{
        mainPanel=new JPanel();
         mainPanel1=new JPanel();
          mainPanel2=new JPanel();
           mainPanel3=new JPanel();
        viewPanel = new JPanel();
        
        //viewPanel.setLayout(new GridLayout(2, 1));
        dualPanel=new JPanel();
       // dualPanel.setLayout(new GridLayout(3,1));
        dualPanel.setLayout(new FlowLayout(1,23,10));
        
        menuBar = new JMenuBar();
        //setLayout(new BorderLayout(5,1));
        Dimension ecran = Toolkit.getDefaultToolkit().getScreenSize();
       // setSize(new Dimension(ecran.width, ecran.height-30));
      //  setPreferredSize(new Dimension(ecran.width, ecran.height-30));
        setPreferredSize(new Dimension(600,740));
        setResizable(false);
        mainPanel.setBackground(new Color(215,228,242));
        mainPanel1.setBackground(new Color(215,228,242));
        mainPanel2.setBackground(new Color(215,228,242));
        mainPanel3.setBackground(new Color(215,228,242));
        mainPanel.setLayout(new GridLayout(3, 1));
        mainPanel.setName("mainPanel");
        
        //parfait2000


        
        
        //viewPanel.setBorder(new LineBorder(viewPanel.getBackground(), 5));

        scrollPane = new JScrollPane(viewPanel);
        //scrollPane2 = new JScrollPane(dualPanel);
        //jsp.setPreferredSize(new Dimension(ecran.width-20, ecran.height-200));
        //jsp.scrollRectToVisible(new Rectangle(ecran.width-20, ecran.height-200));
        //viewPanel.setPreferredSize(new Dimension(ecran.width-20, ecran.height-200));
        //scrollPane.getViewport().add(viewPanel,null);
       // scrollPane2.getViewport().add(dualPanel,null);
        //jsp.setAutoscrolls(true);
        getContentPane().add(mainPanel,BorderLayout.NORTH);
        getContentPane().add(scrollPane,BorderLayout.SOUTH);
        getContentPane().add(dualPanel,BorderLayout.CENTER);

     
        setJMenuBar(menuBar);


        //buttonPanel.setBackground(Color.white);
        //buttonPanel.setName("buttonPanel");
        //menuBar.setName("menuBar");
        //mainPanel.setPreferredSize(new Dimension(500, 50));
        //buttonPanel.setPreferredSize(new Dimension(500, 40));
        //setPreferredSize(new Dimension(500, 136));
        JMenu menuFile = new JMenu("Fichier");
        menuBar.add(menuFile);
        Utility.addMenuItem(this, menuFile, "Ouvrir", "creation", KeyEvent.VK_O);
        menuFile.addSeparator();
        Utility.addMenuItem(this, menuFile, "Propriété", "properties", KeyEvent.VK_D);
        menuFile.addSeparator();
        Utility.addMenuItem(this, menuFile, "Quitter", "exit", KeyEvent.VK_Q);

        menuBrique = new JMenu("Briques");
        menuBar.add(menuBrique);

        JMenu menuHelp = new JMenu("Aide");
        menuBar.add(menuHelp);
        Utility.addMenuItem(this, menuHelp, "Aide", "help", KeyEvent.VK_F1);
        Utility.addMenuItem(this, menuHelp, "A propos de...", "about", -1);
        //setResizable(false);
        //setLocationRelativeTo(null);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        //setVisible(true);
    }

public void voirStructure() throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException{
        rootEl = Utility.getElement(this.url);

        rootE2 = Utility.getElement(this.url2);
        Element rootE3 = Utility.getElement(this.url3);

        listBriques = new ArrayList<Element>();
        System.out.println("Membre "+rootEl);
        //int id = Integer.parseInt(rootEl.getAttribute("id"));

        Calendar c = new GregorianCalendar();
        String dia;
        String mes;
        String annio;
        dia = Integer.toString(c.get(Calendar.DATE));
        mes = Integer.toString(c.get(Calendar.MONTH)+1);
        annio = Integer.toString(c.get(Calendar.YEAR));
        String fecha="";
        if (c.get(Calendar.MONTH)+1<=9){
            if(c.get(Calendar.DATE)<=9)
                 fecha=("0"+dia+"/0"+mes+"/"+annio);
            else
                 fecha=(""+dia+"/0"+mes+"/"+annio);
        }
        if (c.get(Calendar.MONTH)+1>=10){
            if(c.get(Calendar.DATE)<=9)
                 fecha=("0"+dia+"/"+mes+"/"+annio);
            else
                 fecha=(""+dia+"/"+mes+"/"+annio);
        }
        System.out.println (fecha);

        String combo3;
        
        NodeList nodeListUsers = rootE3.getElementsByTagName("NomUtilisateur");
        Element user = (Element) nodeListUsers.item(0);
        combo3=user.getTextContent();
        //System.out.println ("veamos"+combo3);
        

        String combos2;
        //String combos =rootE2.getAttribute("nom");
        //System.out.println ("ddd"+combos);
        nodeListClasses = rootE2.getElementsByTagName("Classe");
        String [] ensemble=new String [nodeListClasses.getLength()];


        int z=0;
        int filtro=0;
        boolean encontrado=false;
        for(int j=0; j<nodeListClasses.getLength();j++){
            Element classe = (Element) nodeListClasses.item(j);
            combos2 = classe.getAttribute("nom");
            encontrado=false;
            for(int y=0;y<z;y++)
            {  if(ensemble[y].equals(combos2)){
               encontrado=true;
               }
            }
            
            if(!encontrado && combo3.equals(classe.getAttribute("instituteur")))
            {ensemble[z]=combos2;
               filtro=z;
               z++;               
            }
        }

        String [] filtrado=new String [filtro+2];
         filtrado[0]="";
         for(int x=1;x<=filtro+1;x++)
            {  filtrado[x]=ensemble[x-1];
               //System.out.println (filtrado[x]);
            }


         /*********//*********//*********//*********//*********//*********/
         /*********//*********//*********//*********//*********//*********/
         //Id structure profil + _Groupe_ + nom profil du groupe + .xml’
         /*********//*********//*********//*********//*********//*********/
         NomGroupe=rootEl.getAttribute("id")+"_Groupe_"+jTitre.getText()+".xml";
         System.out.println (NomGroupe);
         /*********//*********//*********//*********/   /*********//*********/


        String nom = rootEl.getAttribute("nom")+rootEl.getAttribute("createur");
        //System.out.println (nom);
        JLabel nomStructure = new JLabel("Nom de la Structure:   "+nom);
        JLabel dateCreation= new JLabel("Date de Creation du Groupe:   "+fecha+"    ");
        JLabel nomUtilisateur = new JLabel("Createur du Groupe:   "+combo3+"     ");
        parte1=new JLabel("Nom du Profil:   "+rootEl.getAttribute("id")+"_Groupe_");
        nomStructure.setFont(new Font("Bradley Hand ITC",Font.BOLD,20));
        dateCreation.setFont(new Font("Calibri",Font.PLAIN,16));
        nomUtilisateur.setFont(new Font("Calibri",Font.PLAIN,16));
        jTitre.setPreferredSize(new Dimension(220, 20));

        jTitre.setFont(new Font("Calibri",Font.PLAIN,16));
        parte1.setFont(new Font("Calibri",Font.PLAIN,16));
        parte3.setFont(new Font("Calibri",Font.PLAIN,16));

        mainPanel1.add(nomStructure);
        mainPanel2.add(dateCreation);
        mainPanel2.add(nomUtilisateur);

        mainPanel3.add(parte1);
        mainPanel3.add(jTitre);
        mainPanel3.add(parte3);
        
        mainPanel.add(mainPanel1,BorderLayout.NORTH);
        mainPanel.add(mainPanel2,BorderLayout.CENTER);
        mainPanel.add(mainPanel3,BorderLayout.SOUTH);

        
        
        comboClasses = new JComboBox(filtrado);

        comboClasses.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboClassesItemStateChanged(evt);
            }
        });

        JLabel selection= new JLabel("Selectioner la classe");
        //System.out.println(mainPanel+" / "+mainPanel.getComponents().length);
        Dimension ecran = Toolkit.getDefaultToolkit().getScreenSize();
        NodeList nodeListBriques = rootEl.getElementsByTagName("brique");
        ComposantsView lv = new ComposantsView(ecran);
       // ListeView lv = new ListeView(ecran);
        for(int i=0; i<nodeListBriques.getLength();i++){
            Element brique = (Element) nodeListBriques.item(i);
            listBriques.add(brique);
            int type = Integer.parseInt(brique.getAttribute("type"));

            if (type<=2){
            lv.ajouter(listBriques.get(i));
            
            String nomBrique = brique.getAttribute("nom");

            if(nomBrique.equals(null) || nomBrique.equals("")){
                /*JButton briqueBouton = new JButton("Commentaires");
                briqueBouton.setActionCommand(Integer.toString(i));
                briqueBouton.addActionListener(this);
                mainPanel.add(briqueBouton);*/
                //Utility.addButton(this, buttonPanel, "Commentaires", "Commentaires", Integer.toString(i), null);
                Utility.addMenuItem(this, menuBrique, "Commentaires", Integer.toString(i), -1);
            } else {
                //Utility.addButton(this, buttonPanel, nomBrique, nomBrique, Integer.toString(i), null);
                Utility.addMenuItem(this, menuBrique, nomBrique, Integer.toString(i), -1);
                /*JButton briqueBouton = new JButton(nomBrique);
                briqueBouton.setActionCommand(Integer.toString(i));
                briqueBouton.addActionListener(this);
                mainPanel.add(briqueBouton);*/
            }

       }
   }    lv.montrer();
        viewPanel.add(lv);
          
        dual.setPreferredSize(new Dimension(480,320));
        comboPanel =new JPanel();
        commandPanel=new JPanel();
        JButton creer=new JButton("Creer");
        JButton annuler=new JButton("Annuler");

                creer.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                try {
                    CreationDeXMLActionPerformed(evt);
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SAXException ex) {
                    Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (TransformerConfigurationException ex) {
                    Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (TransformerException ex) {
                    Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                }
                      }
                      });

        commandPanel.add(creer);
        commandPanel.add(annuler);
        comboPanel.add(selection);
        comboPanel.add(comboClasses);

        dualPanel.add(comboPanel);
        dualPanel.add(dual);
        dualPanel.add(commandPanel);
        
        setVisible(true);
    }

private void CreationDeXMLActionPerformed(java.awt.event.ActionEvent evt) throws ParserConfigurationException, SAXException, TransformerConfigurationException, IOException, TransformerException {
       ArrayList<Element> listBriquesG = new ArrayList<Element>();
        JList ListEleves=new JList();
        ListEleves=dual.getListTotale();
        int taille=ListEleves.getModel().getSize();

        System.out.println("taille>>> "+taille);
        //taille=3;

        if (taille>=2)
        {
            NomGroupe=rootEl.getAttribute("id")+"_Groupe_"+jTitre.getText()+".xml";
              totalGroupe=baseGroupe+NomGroupe;
              //System.out.println (totalGroupe);
              //System.out.println (url);
              

              //Element rootE100 = Utility.getElement(this.totalGroupe);
             //rootE100.setAttribute("nom", "5000");
           

              // System.out.println(url);
              //System.out.println(totalGroupe);
              //System.out.println("ça marche");

             // rootGroupe = Utility.getElement(this.totalGroupe);
              
                
             //String nomG = rootGroupe.getAttribute("nom")+rootGroupe.getAttribute("createur");
             //System.out.println("ruta perdida"+nomG);
             // int w=0; System.out.println(baseProfils+"65_Benoit"+w+".xml");
             
             String Ele = baseProfils+rootEl.getAttribute("id")+"_"+ListEleves.getModel().getElementAt(0).toString()+".xml";
             String Ele2 = totalGroupe;
             //String Ele2 = baseGroupe+"temporaire.xml";

             DocumentBuilder db0 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document document0 = db0.parse(Ele);
             Element root = document0.getDocumentElement();
             //root.setAttribute("xxx", "ddddd");
             Element personnes = document0.createElement("Eleves");
            //System.out.print("tammmmmaaa"+dual.getListTotale().getModel().getSize());
             for (int z=0;z<dual.getListTotale().getModel().getSize();z++){
                   System.out.println(dual.getListTotale().getModel().getElementAt(z).toString());
                 Element personne = document0.createElement("Eleve");
			personne.setAttribute("prenom",dual.getListTotale().getModel().getElementAt(z).toString());
              int s=0;
              while(!dual.nn[s].equals(dual.getListTotale().getModel().getElementAt(z).toString())){
                  s++;
              }
                   personne.setAttribute("id",dual.mm[s]);

			personnes.appendChild(personne);
             }
             
             root.appendChild(personnes);

             ope2.transformerXml(document0, Ele2);

             for(int x=1;x<taille; x++ ){
             //  Ele = baseProfils+"65_Benoit"+x+".xml";
             Ele = baseProfils+rootEl.getAttribute("id")+"_"+ListEleves.getModel().getElementAt(x).toString()+".xml";
             String uno;
             uno=ListEleves.getModel().getElementAt(x).toString();
             //System.out.println("**************LISTAAA********"+uno);

             DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document document = db.parse(Ele);
             DocumentBuilder db2 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document document2 = db.parse(Ele2);
                       
            NodeList nodeListBriquesG = document.getElementsByTagName("brique");
       
            for(int i=0; i<nodeListBriquesG.getLength();i++){
            Element briqueG = (Element) nodeListBriquesG.item(i);
            listBriquesG.add(briqueG);
            int typeG = Integer.parseInt(briqueG.getAttribute("type"));

            if (typeG<=2){
            System.out.print("deux types:"+typeG);
            int num=x+1;
           // oppp.ajouter(listBriques.get(i),Ele, totalGroupe, baseGroupe, document);
            ope2.ajouter(NomGroupe,listBriques.get(i), totalGroupe, Ele2 ,document, document2,num,taille);
            //String nomBriqueG = briqueG.getAttribute("nom");

            }
          }
    
    

      //   System.out.println("Valeur de x:"+x);
        }
     }
   }


    
 public void comboClassesItemStateChanged(java.awt.event.ItemEvent evt) {
    String nomclasse= comboClasses.getItemAt(comboClasses.getSelectedIndex()).toString();
    //System.out.println(nomclasse);
    nodeListClasses = rootE2.getElementsByTagName("Classe");
    if(!nomclasse.equals("")){
        int numero=0;
        for(int w=0; w<nodeListClasses.getLength();w++){
            Element classe2 = (Element) nodeListClasses.item(w);
            if(nomclasse .equals(classe2.getAttribute("nom"))){
                numero=w;
            }
        }

        Node eleve = nodeListClasses.item(numero).getFirstChild();
        int r=0;
        while(!eleve.equals(nodeListClasses.item(numero).getLastChild())){
            if (eleve.getNodeName().equals("Eleve")){
               r++;
             }
            eleve = eleve.getNextSibling();
        }

        String []eleves = new String [r];
        String []ids = new String [r];

        r=0;
        eleve = nodeListClasses.item(numero).getFirstChild();
        while(!eleve.equals(nodeListClasses.item(numero).getLastChild())){
            if (eleve.getNodeName().equals("Eleve")){
                eleves[r]=((Element) eleve).getAttribute("prenom");
                ids[r]=((Element) eleve).getAttribute("id");

               // System.out.println (ids[r]+" >>>>>>>>> "+eleves[r]);
                r++;
             }
            eleve = eleve.getNextSibling();
        }

             nomclasse= nomclasse.replace("à", "a");
             nomclasse= nomclasse.replace("é", "e");
             nomclasse= nomclasse.replace("è", "e");
             nomclasse= nomclasse.replace("í", "i");
             nomclasse= nomclasse.replace("ï", "i");
             nomclasse= nomclasse.replace("ó", "o");
             nomclasse= nomclasse.replace("ú", "u");
             nomclasse= nomclasse.replace("ù", "u");
             nomclasse= nomclasse.replace("/", "-");

        dual.setEleves(eleves.length, eleves, ids);
        dual.setSourceElements(eleves);
        dual.clearDestinationListModel();
        jTitre.setText(nomclasse);
       

        mainPanel3.add(parte1);
        mainPanel3.add(jTitre);
        mainPanel3.add(parte3);

        mainPanel.add(mainPanel1,BorderLayout.NORTH);
        mainPanel.add(mainPanel2,BorderLayout.CENTER);
        mainPanel.add(mainPanel3,BorderLayout.SOUTH);

        
        
}else{
        dual.clearSourceListModel();
        dual.clearDestinationListModel();
        jTitre.setText("");
        mainPanel3.add(parte1);
        mainPanel3.add(jTitre);
        mainPanel3.add(parte3);

        mainPanel.add(mainPanel1,BorderLayout.NORTH);
        mainPanel.add(mainPanel2,BorderLayout.CENTER);
        mainPanel.add(mainPanel3,BorderLayout.SOUTH);

        
}
        
    
    }

  public void actionPerformed(ActionEvent e) {

        String c = e.getActionCommand();
        
        System.out.println("--->>>"+c);
        if (c.equals("exit")) {
            Utility.exit();
        } else if(c.equals("creation")){
            JFileChooser jfc2 = Utility.ouvrirOpenBox2(url,null);
            if(jfc2!=null){
                String chemin = jfc2.getSelectedFile().getAbsolutePath();
               
                try {
                    try {
                        reset(chemin);
                    
                    } catch (TransformerConfigurationException ex) {
                        Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerException ex) {
                        Logger.getLogger(GroupeView.class.getName()).log(Level.SEVERE, null, ex);
                    }
                   
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SAXException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else if(c.equals("properties")){
            App.getApplication().show(new GroupeProperties(url));
        } else if (c.equals("help")){

        }else if (c.equals("creer")){
         App.getApplication().show(new GroupeProperties(url));
        
            
        }
        else if (c.equals("about")){
            App.getApplication().show(new GroupeAbout());
        } else {
            for (int i=0; i<listBriques.size(); i++){
                String nomBrique = listBriques.get(i).getAttribute("nom");
                if(c.equals(Integer.toString(i))){
                    System.out.println("-->>"+nomBrique);
                    if(viewPanel!=null){
                        viewPanel.removeAll();
                    } else {
                        //setSize(new Dimension(400, 400));
                        Dimension ecran = Toolkit.getDefaultToolkit().getScreenSize();
                        setSize(new Dimension(ecran.width, ecran.height-30));
                        viewPanel = new JPanel();
                        scrollPane=new JScrollPane(viewPanel);
                        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                        //jsp.setViewportBorder(new LineBorder(Color.RED));
                        scrollPane.getViewport().add(viewPanel, null);

                        //jsp.setVerticalScrollBar(new JScrollBar());
                        getContentPane().add(scrollPane,"South");
                    }

                    int type = Integer.parseInt(listBriques.get(i).getAttribute("type"));
                    updateBriques(i);
                    //System.out.println("brique "+Integer.toString(i)+" : "+menuBrique.getItem(i).getText());
                    switch(type){
                        case 0:

                            //ComposantsView lv = new ComposantsView(listBriques.get(i));
                            /*JScrollPane test = new JScrollPane(lv);
                            test.setPreferredSize(new Dimension(500, 600));*/
                            //this.add(test);
                            //JScrollBar jb = new JScrollBar();
                            //jsp.getViewport().add(lv, null);
                            //viewPanel.add(lv);
                            //viewPanel.add(jb,"East");
                            //
                            //lv.drawIt();
                            //lv.pa
                            //Dimension ecran = Toolkit.getDefaultToolkit().getScreenSize();
                            //int he = ecran.height-30;

                            //buttonPanel.setPreferredSize(new Dimension(ecran.width, test-104));
                            /*lv.setPreferredSize(new Dimension(lv.dimension.width,lv.dimension.height*21));
                            setSize(new Dimension(ecran.width, ecran.height));*/

                            /*if (lv.dimension.height*21>ecran.height-this.test-30){
                                System.out.println("dans if max="+lv.dimension.height+" / frame="+this.getHeight());
                                lv.setPreferredSize(new Dimension(lv.dimension.width,lv.dimension.height*21));
                                setSize(new Dimension(ecran.width, 150+lv.dimension.height*21));
                            } else {
                                System.out.println("dans else max="+lv.dimension.height*21+" / frame="+this.getHeight()+" / ecran="+ecran.height+" / test="+test);
                                lv.setPreferredSize(new Dimension(lv.dimension.width,ecran.height-this.test-50));
                                setSize(new Dimension(ecran.width, ecran.height-30));
                            }*/
                            //setSize(new Dimension(ecran.width, ecran.height-30));
                            /*if (lv.dimension.width>this.getWidth()){
                                //System.out.println("dans if max="+lv.dimension.width+" / frame="+this.getWidth());
                                lv.setPreferredSize(new Dimension(lv.dimension.width,lv.dimension.height*21));
                                setSize(new Dimension(lv.dimension.width, 150+lv.dimension.height*21));
                            } else {
                                //System.out.println("dans else max="+lv.dimension.width+" / frame="+this.getWidth());
                                lv.setPreferredSize(new Dimension(this.getWidth(),lv.dimension.height*21));
                                setSize(new Dimension(this.getWidth(), 150+lv.dimension.height*21));
                            }*/
                            //viewPanel.setPreferredSize(new Dimension(lv.dimension.width,lv.dimension.height*21));

                            //setSize(new Dimension(400, 400));
                           //lv.setPreferredSize(new Dimension(500,500));
                            setVisible(true);
                            //setSize(new Dimension(this.getWidth(), 650));



                            setLocationRelativeTo(null);
                            return;
                        case 1:
                            //RepartitionView rv = new RepartitionView(listBriques.get(i),ecran);

                            //viewPanel.add(rv);
                            //getContentPane().add(viewPanel,"South");
                            //int dim1 = rv.drawIt();
                            //rv.setPreferredSize(new Dimension(500, dim1*21));
                            //this.setSize(new Dimension(550, 150+dim1*21));
                            setLocationRelativeTo(null);
                            return;
                        case 2:
                            /*GrapheView gv = new GrapheView(listBriques.get(i));

                            viewPanel.add(gv);*/
                            //getContentPane().add(viewPanel,"South");
                            //gv.drawIt();
                            //gv.setPreferredSize(new Dimension(200,200));

                            setLocationRelativeTo(null);
                            setVisible(true);
                            return;
                        case 3:
                            /*CommentaireView cv = new CommentaireView(listBriques.get(i));
                            viewPanel.add(cv);*/
                            /*ComposantsView lv = new ComposantsView(listBriques.get(i));
                            lv.setPreferredSize(new Dimension(200, 200));
                            viewPanel.add(lv);
                            getContentPane().add(viewPanel,"South");
                            lv.drawIt();*/
                            setVisible(true);
                            //setSize(new Dimension(this.getWidth(), 150+50));
                            setLocationRelativeTo(null);
                            return;
                    }

                }
                //System.out.println("-->>i= "+i);
            }
        }
    }

    private void reset(String chemin) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException {
        this.url = chemin;
        ResourceMap resourceMap = Application.getInstance(groupe.App.class).getContext().getResourceMap(App.class);
        setTitle(resourceMap.getString("Application.title")+" ("+url.substring(url.lastIndexOf("\\")+1,url.length())+")");
        //setTitle("PERL ("+url.substring(url.lastIndexOf("\\")+1,url.length())+")");
        //getContainerListeners();
        //setVisible(true);
        mainPanel.removeAll();
        //buttonPanel.removeAll();
        //if(viewPanel!=null)
        viewPanel.removeAll();

        Element rootEl = Utility.getElement(this.url);
        //listBriques = new ArrayList<Element>();
        //System.out.println("Membre "+rootEl);
        //int id = Integer.parseInt(rootEl.getAttribute("id"));

        String nom = rootEl.getAttribute("nom_eleve")+" "+rootEl.getAttribute("prenom_eleve");

        JLabel nomEtu = new JLabel(nom);
        nomEtu.setFont(new Font("Bradley Hand ITC",1,30));

        mainPanel.add(nomEtu);


        //mainPanel.add(new JLabel("hello"));
        //remove(viewPanel);
        //this.removeAll();
        /*for (int i=0; i<mainPanel.getContainerListeners().length; i++){
            mainPanel.getContainerListeners()[i]=null;
        }*/
        //System.out.println(getContentPane().getComponents().length);
        //set
        //mainPanel = new JPanel();
        //JLabel nomStructure = new JLabel("nom");
        //nomStructure.setSize(20, 20);
        //mainPanel.add(nomStructure);

        //getContentPane().add(mainPanel);
        //setVisible(true);
        //App.getApplication().show(this);
        initComponents();
        //setSize(500, 500);

        voirStructure();
        setLocationRelativeTo(null);
        this.
        setVisible(true);
    }

    private void updateBriques(int index){
        System.out.println(menuBrique.getItemCount());
        for(int i=0; i<menuBrique.getItemCount(); i++){

            if(i==index){
                menuBrique.getItem(i).setEnabled(false);
            } else {
                menuBrique.getItem(i).setEnabled(true);
            }
        }
    }
}
